package com.ai.entity.made.page;

import com.ai.entity.made.Slabs;
import com.ai.entity.comm.page.SysBasePage;
import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SlabsPages extends SysBasePage<Slabs> {

    @ApiModelProperty("板坯号")
    private String slabNum;

    @ApiModelProperty("产线")
    private Integer productLines;

    @ApiModelProperty("异常多选")
    private Integer[] unusuals;

    @Override
    public QueryWrapper<Slabs> getQuery(QueryWrapper<Slabs> queryWrapper) {
        queryWrapper.orderByDesc("id").eq("upper_visible", 1);

        if (unusuals != null && unusuals.length > 0) {
            for (int i = 0, length = unusuals.length; i < length; i++) {
                switch (unusuals[i]) {
                    case 1:
                        queryWrapper.gt("unusual1", 0);
                        break;
                    case 2:
                        queryWrapper.gt("unusual2", 0);
                        break;
                    case 3:
                        queryWrapper.gt("unusual3", 0);
                        break;
                    case 4:
                        queryWrapper.gt("unusual4", 0);
                        break;
                    case 5:
                        queryWrapper.gt("unusual5", 0);
                        break;
                }
            }
        }

        queryWrapper.like((!StringUtils.isEmpty(slabNum)), "slab_num", slabNum)
                .eq((productLines != null && productLines != 0), "product_lines", productLines)
                .ge((!StringUtils.isEmpty(getDatebegin())), "upper_time", getDatebegin())
                .lt((!StringUtils.isEmpty(getDateend())), "upper_time", getDateend());
        return queryWrapper;
    }
}
